#ifndef SLAM_ROS_SLAM_ROS_CLEAR_LOG_FILE_H_
#define SLAM_ROS_SLAM_ROS_CLEAR_LOG_FILE_H_

#include <dirent.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <vector>

namespace slam_ros {

struct LogFilePathAndMaxNum {
  LogFilePathAndMaxNum(const std::string &path, const int retained_num)
      : path(path), retained_num(retained_num) {}
  std::string path;
  int retained_num;
};

struct FileAndTime {
  FileAndTime(const std::string &file_name, const std::time_t &file_time)
      : file_name(file_name), file_time(file_time) {}
  std::string file_name;
  std::time_t file_time;
};

class ClearLogFile {
 public:
  ClearLogFile() = delete;
  ClearLogFile(
      const std::vector<LogFilePathAndMaxNum> &log_path_and_retained_num);

  ~ClearLogFile();
  void RemoveOldLogFIle(const std::string &dir_name, const int retained_num);
  void AutoRemoveOldLogFIle();

 private:
  void GetAllFileAndTimeInDir(const std::string &dir_name,
                              std::vector<FileAndTime> *files);

 private:
  std::vector<LogFilePathAndMaxNum> log_path_and_retained_num_;
};
}  // namespace slam_ros

#endif